#include <bits/stdc++.h>
using namespace std;

// 【题目】力扣001. 两数之和
// 【难度】简单
// 【提交】https://leetcode.cn/problems/two-sum/submissions/663377045/
// 【标签】数组；哈希表
class Solution {
public:
    std::vector<int> twoSum(std::vector<int>& nums, int target) {
        std::unordered_map<int, int> hash_map;
        
        for (int i = 0; i < nums.size(); ++i) {
            int complement = target - nums[i];
           
            if (hash_map.find(complement) != hash_map.end()) {
                return {hash_map[complement], i};
            }
            
            hash_map[nums[i]] = i;
        }
        
        return {};
    }
};